import Mock from 'mockjs'
const Random=Mock.Random;

Mock.mock('/api/user','get',{
    code:200,
    message:"操作成功",
    data:{
        id:1,
        name:Random.cname(),
        gender:Random.pick(["男","女"]),
        birthday:Random.date(),
        email:Random.email(),
        bio:Random.csentence(10,10),
    },
})

const users=Mock.mock({
    'list|1-10':[{
        'id|+1':1,
        name:()=>Random.cname(),
        gender:()=>Random.pick(["男","女"]),
        birthday:()=>Random.date(),
        email:()=>Random.email(),
        bio:()=>Random.csentence(10,10),
    }]
})

Mock.mock('/api/user/getList','get',{
    code:200,
    message:"操作成功",
    data:users.list,
})
Mock.mock('//api/user/getUserById','get',(req,res)=>{
    const id=req.url.match(/id=(\d+)/)[1];
    const user=users.list.find((user)=>(user.id=id));
    return{
        code:200,
        message:"操作成功",
        data:user,
    };
});